package cn.nbs.book.dao;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import cn.com.hkr.jdbc.TxQueryRunner;
import cn.nbs.book.entity.Book;

public class BookDao {
	private TxQueryRunner qr = new TxQueryRunner();

	/**
	 * 通过cid查询图书
	 * @param cid
	 * @return
	 */
	public List<Book> findByBookCid(String cid) {
		String sql = "select * from t_book  where cid = ?";
		try {
			return qr.query(sql, new BeanListHandler<Book>(Book.class),cid);
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

	/**
	 * 通过bid查询图书
	 * @param bid
	 * @return
	 */
	public Book findByBid(String bid) {
		String sql = "select *  from t_book where bid = ?";
		try {
			return qr.query(sql , new BeanHandler<Book>(Book.class),bid);
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}
	
}
